﻿namespace OboutInc.EasyMenu_Pro
{
    using System;
    using System.Collections;
    using System.ComponentModel;
    using System.Reflection;
    using System.Web.UI;

    [Serializable, ToolboxItem(false)]
    public class CSSClassesCollection : CollectionBase, INamingContainer
    {
        public int Add(CSSClasses menuComponentCSSClasses)
        {
            if ((menuComponentCSSClasses.ObjectType == null) || (menuComponentCSSClasses.ObjectType == string.Empty))
            {
                return -1;
            }
            int index = this.IndexOf(menuComponentCSSClasses);
            if (index == -1)
            {
                return base.InnerList.Add(menuComponentCSSClasses);
            }
            if (!menuComponentCSSClasses.equalsToDefault())
            {
                this[index] = menuComponentCSSClasses;
            }
            return index;
        }

        public int IndexOf(object obj)
        {
            if (obj is int)
            {
                return (int) obj;
            }
            if (obj is string)
            {
                for (int j = 0; j < base.List.Count; j++)
                {
                    if ((((CSSClasses) base.List[j]).ObjectType == obj.ToString()) || (((CSSClasses) base.List[j]).ObjectType == obj.ToString()))
                    {
                        return j;
                    }
                }
                return -1;
            }
            if (obj is CSSClasses)
            {
                for (int k = 0; k < base.List.Count; k++)
                {
                    if (((CSSClasses) base.List[k]).ObjectType == ((CSSClasses) obj).ObjectType)
                    {
                        return k;
                    }
                }
                return -1;
            }
            if (!(obj is Type))
            {
                throw new ArgumentException("Only a string or an integer is permitted for the indexer.");
            }
            for (int i = 0; i < base.List.Count; i++)
            {
                if (((CSSClasses) base.List[i]).ObjectType == ((Type) obj).FullName)
                {
                    return i;
                }
            }
            return -1;
        }

        private void Remove(CSSClasses menuComponentCSSClasses)
        {
            base.InnerList.Remove(menuComponentCSSClasses);
        }

        private void Remove(int index)
        {
            base.InnerList.RemoveAt(index);
        }

        public void Render(HtmlTextWriter writer)
        {
            writer.Write("{");
            bool flag = true;
            foreach (CSSClasses classes in base.List)
            {
                if (!flag)
                {
                    writer.Write(",");
                }
                classes.Render(writer);
                flag = false;
            }
            writer.Write("}");
        }

        public CSSClasses this[object obj]
        {
            get
            {
                return (CSSClasses) base.List[this.IndexOf(obj)];
            }
            set
            {
                base.List[this.IndexOf(obj)] = value;
            }
        }
    }
}

